Compilation optimization #14
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Yes, it involves an additional automatic optimization step just before runtime, after the HScript parsing is completed.
This includes:
x = 10 + 20tox = 30.For example:
becomes
...among others.
Newly Added Parameters:
optimizeEnabled: BooloptimizeLevel: IntenableConstantFolding: BoolenableExpressionSimplification: BoolenableDeadCodeElimination: BoolenableBranchOptimization: BooloptimizerDebug: BoolTotal: 7 options.
Most are self-explanatory. Let me describe the ones that might be less clear:
optimizeLevel: Sets the maximum number of optimization passes. It determines how many times the optimizer will attempt to optimize the HScript code. However, there is a built-in check to see if further optimization is possible. In most cases, only 1 to 3 passes are needed.optimizerDebug: When enabled, it outputs the code structure (AST) both before and after optimization.The optimization process happens within the
executephase and does not affect runtime performance at all.Regarding optimization speed: for a large script (22KB), three optimization passes take about 22 milliseconds, averaging 7.33ms per pass. I believe this should be perfectly acceptable.
Additionally, I have tested whether the optimization results remain consistent with the original code. I can only say that I tested as thoroughly as possible, and no issues were found—even when running large mods.